package com.djl.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.djl.ud.OrderDao;
import com.djl.user.Order;

public class UpdateOrderServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		HttpSession session =request.getSession();
		int id= Integer.parseInt(request.getParameter("id"));
		List<Order> list = new ArrayList<Order>();
		OrderDao orderDao = new OrderDao();
		if(id!=0){
		try {
			list = orderDao.getIdAll(id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		session.setAttribute("upAll", list);
		request.getRequestDispatcher("manage/order-modify.jsp").forward(request, response);
		}else{
			response.sendRedirect("OrderServletAll");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			Order order = new Order();
			int id=Integer.parseInt(request.getParameter("orderId"));
			String name=request.getParameter("name");
			String city=request.getParameter("city");
			int status =Integer.parseInt(request.getParameter("status"));
			order.setEo_id(id);
			order.setEo_user_name(name);
			order.setEo_user_address(city);
			order.setEo_status(status);
			OrderDao od = new OrderDao();
			try {
				od.update(order);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			response.sendRedirect("OrderServletAll");
	}
}
